package com.bjwl.modules.back.controller;

import com.bjwl.common.utils.PageUtils;
import com.bjwl.common.utils.R;
import com.bjwl.modules.common.pojo.MyPage;
import com.bjwl.modules.back.entity.UserEntity;
import com.bjwl.modules.back.services.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

/**
 * 学员信息表
 *
 * @author guoyp
 * @email guoyp2126@163.com
 * @date 2021-11-20 17:22:25
 */
@RestController
@RequestMapping("back/user")
public class UserController {
    @Autowired
    private UserService userService;
    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        try {
            MyPage myPage = new MyPage(params);
            String userName = params.get("userName").toString();

            PageUtils page = userService.queryPage(myPage,userName);
            return R.ok().put("data", page);
        } catch (Exception e){
            return R.error(e.getMessage());
        }
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody UserEntity user){
        userService.save(user);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody UserEntity user){
        userService.updateById(user);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
        userService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
